package com.amkai.aes.webservice.binary.objecthandler.inventory;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import org.hibernate.Query;

import com.amkai.aes.aescommon.service.binary.job.Job;
import com.amkai.aes.aescommon.service.binary.job.inventory.PurchaseOrderLinesJob;
import com.amkai.aes.aescommon.service.binary.job.inventory.VendorOrderManufacterJob;
import com.amkai.aes.generatedbeans.common.Organization;
import com.amkai.aes.generatedbeans.inventory.VendorOrderInformation;
import com.amkai.aes.generatedbeans.inventory.purchasing.PurchaseOrderLine;
import com.amkai.aes.webservice.binary.JobObjectHandler;
import com.amkai.common.extensions.hibernate.config.SiteManager;
import com.amkai.common.extensions.hibernate.config.manager.SessionManager;

public class VendorOrderManufacterHandler implements JobObjectHandler <VendorOrderManufacterJob,Serializable, Organization> {

	private static final String query = "select org from Organization org where :voId in (select vo from org.vendorVendorOrderInformations vo)";
	@Override
	public Organization process(VendorOrderManufacterJob job, Serializable object) throws Exception {
		SessionManager sm = SiteManager.Start();
		try {
			sm.openSession();
			//#14264
//			Query q;
//			q = sm.execute(query);
//			q.setLong("voId",job.voId);
//			
//			return  (Organization)q.uniqueResult();
			VendorOrderInformation voi = sm.get(VendorOrderInformation.class, job.voId);
			if (voi.getManufacturer() != null) {
				voi.getManufacturer().getContactName();
				voi.getManufacturer().getDescription();
				voi.getManufacturer().getBaseOrganization();
			}
			if (voi.getVendor() != null) {
				voi.getVendor().getBaseOrganization();
				voi.getVendor().getDescription();
				voi.getVendor().getContactName();
			}
			return voi.getManufacturer();
		
		} catch (Exception e) {
			throw e;
		} finally {
			sm.closeSession();
		}	
	}

}
